package com.yiwenup.leetcode.site;

import com.yiwenup.leetcode.ListNode;

/**
 * https://leetcode-cn.com/problems/reverse-linked-list/
 */
public class No206 {

    public ListNode reverseList1(ListNode head) {
        if (head == null || head.next == null) return head;

        ListNode node = reverseList1(head.next);
        head.next.next = head;
        head.next = null;
        return node;
    }

    public ListNode reverseList2(ListNode head) {
        ListNode pre = null;
        ListNode cur = head;

        while (cur != null) {
            ListNode node = cur.next;
            cur.next = pre;
            pre = cur;
            cur = node;
        }

        return pre;
    }
}
